#include <unistd.h>
#include <stdio.h>
#include <sys/types.h>

int main(int argc, char *argv[])
{
    printf("父进程开始执行,pid:%d\n",getpid());
    int val = 100;
    
    pid_t pid = fork();
    if(pid == -1)
    {
        printf("创建子进程失败\n");
        return -1;
    }
    else if(pid == 0)
    {
        printf("子进程开始执行,pid:%d,父进程pid是:%d\n",getpid(),getppid());
        printf("子进程的val:%d\n",--val);
    }
    else
    {
        printf("父进程执行,pid:%d,子进程pid是:%d\n",getpid(),pid);
        printf("父进程的val:%d\n",++val);
    }
    
    if (pid == 0)
    {
        printf("子进程结束\n");
    }
    else
    {
        printf("父进程结束\n");
    }
    
    
    return 0;
}